package com.qen.fx.tools;

import com.alibaba.fastjson2.JSONArray;
import com.qen.App;
import com.qen.fx.ViewIndex;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;

public class MenuTools {

    public static JSONArray getMenus() {
        InputStream inputStream = App.class.getResourceAsStream(ViewIndex.MenuJson);

        if (inputStream != null) {
            // 使用BufferedReader读取文件内容
            BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8));
            String line;
            StringBuilder content = new StringBuilder();

            try {
                while ((line = reader.readLine()) != null) {
                    content.append(line).append("\n");
                }
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                try {
                    reader.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return JSONArray.parseArray(content.toString());
        } else {
            return null;
        }
    }
}
